package com.jerry.cui.dingtalk;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.jerry.cui.dingtalk.oauth2.DefaultDingtalkOAuth2AccessToken;
import com.jerry.cui.dingtalk.oauth2.DefaultDingtalkToken;
import com.jerry.cui.dingtalk.oauth2.DingtalkOAuth2AccessToken;
import com.jerry.cui.dingtalk.oauth2.DingtalkToken;
import com.jerry.cui.dingtalk.properties.DingtalkProperties;

@Configuration
public class DingtalkOauth2BeanConfigure {

    @Autowired
    private DingtalkProperties dingtalkProperties;

    @Autowired
    private DingtalkToken dingtalkToken;

    @Bean
    @ConditionalOnMissingBean(DingtalkToken.class)
    public DingtalkToken dingtalkToken(){
        DingtalkToken dingtalkToken = new DefaultDingtalkToken(dingtalkProperties.getApi().getGet_token(),dingtalkProperties.getCorp().getCorpId(),dingtalkProperties.getCorp().getCorpSecret());
        return dingtalkToken;
    }

    @Bean
    @ConditionalOnMissingBean(DingtalkOAuth2AccessToken.class)
    public DingtalkOAuth2AccessToken dingtalkOAuth2AccessToken(){
        DingtalkOAuth2AccessToken dingtalkOAuth2AccessToken = new DefaultDingtalkOAuth2AccessToken(dingtalkToken);
        return dingtalkOAuth2AccessToken;
    }
}
